package com.tedu.egmvc.controller;

import com.tedu.egmvc.mapper.ProductMapper;
import com.tedu.egmvc.pojo.dto.ProductDTO;
import com.tedu.egmvc.pojo.entity.Product;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "信息模块")
@RestController
public class ProductController {
    @Autowired
    private ProductMapper productMapper;

    @ApiOperation("添加地址")
    @PostMapping("/addressInsert")
    public String insert(ProductDTO productDTO){
        Product product=new Product();
        BeanUtils.copyProperties(productDTO,product);
        System.out.println(product);
        productMapper.insertAddress(product);
        return "添加成功";
    }

    @ApiOperation("查找全部信息")
    @GetMapping("/addressSelect")
    public List<Product> find(){
        List<Product> productList=productMapper.findAll();
        return productList;
    }

    @ApiOperation("删除收货地址")
    @DeleteMapping("/address/delete/{id}")
    public String deleteById(@PathVariable int id){
        int num=productMapper.deleteAddress(id);
        return num>0?"删除成功":"删除失败";
    }

    @ApiOperation("修改收货地址")
    @PutMapping("/addressUpdate")
    public String updateById(Product product){
        int num=productMapper.updateAddress(product);
        return num>0?"修改成功":"修改失败";
    }

}
